﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using HuoTu.Common;
namespace ExampleWeb
{
    public partial class RSA : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            //长度只允许117
            string content = @"http://api.fanmore.cn/Api.ashx?req=Login&operation=HuoTu2013AD&qd=HuoTu&version=1.2.0&citycode=179&imei=3598361112345";
            string xmlPrivateKeys, xmlPublicKey;
            //SysCrypto.RSAKey(out xmlPrivateKeys, out xmlPublicKey);
            xmlPrivateKeys = "<RSAKeyValue><Modulus>1K2eMCDWO53Q/YAGioQ3OyVRSObM6laSJ6422Z4kDv+eoBXVqy6OdYw0F9FFAAhLvLbcq/0+PK14ViP4lOJGgufhNVsfywXpvuP/sBNPZqXeOTI/DJZhbMsxv+ZzoIsIWVKpmELuEYpqc6qrl10fxNfZ6oIlRpT+lZ3r/weEjms=</Modulus><Exponent>AQAB</Exponent><P>7ZHNgOhLgGeLUeTxTQZbmFY8SxPvtFZ7Qv04HaEoro2G35OzwHi0ua+8Vyd4tLYsIFEK4g7tgTF3eIkv7hmZjQ==</P><Q>5S13Uc6Yk2O8ShRQ6bLxjG0ostYjDgYi0BFhNZ+2Kg/48AgfMztOpB4Z/OXOppq8wcEh0y5SQcUAgfwYOaY91w==</Q><DP>LlaFHgKxT19i9ltQkbSOwxz277H4zFUd/8gCXQ0lMT7bstpNclpY7esQMnO5gI4T9023cLZ2rv9mDTW9CpUltQ==</DP><DQ>l+jgS6Cm8CPPHkeDLrWHeS6uKITaraQRlVu/1Nyt0gnOV8T6cWohgZXWYhUuOq8c6U2Mj0AIFEJySLcCk8wG9w==</DQ><InverseQ>4S0tUkjnzjSPK/vjOKbmTrobeKRcS59EImZRmaGgQCaHwzQdgy7EyCIebP2XMDXRj4wdkslHkpC6CBMVu5QZ5A==</InverseQ><D>sABZ56RVBhMNL6wyPZE7D8RLJ1RxAgDQhOwEUkUvvAXIZNyM7VPi6t4zAf7Z5jP3UV3W8rHpPlekPU0ZW0SCajJt2ttYTL7TfYzqXSJuSP7xj+ka5YCS1evGkxa/q1IWYJi23bE57x72ILLc4oMMiDU2rhiTb4mC09w0lWRLK9k=</D></RSAKeyValue>";
            xmlPublicKey = "<RSAKeyValue><Modulus>1K2eMCDWO53Q/YAGioQ3OyVRSObM6laSJ6422Z4kDv+eoBXVqy6OdYw0F9FFAAhLvLbcq/0+PK14ViP4lOJGgufhNVsfywXpvuP/sBNPZqXeOTI/DJZhbMsxv+ZzoIsIWVKpmELuEYpqc6qrl10fxNfZ6oIlRpT+lZ3r/weEjms=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

            Response.Write("要加密的内容为：" + content + "<br>");
            Response.Write(string.Format(@"私钥：{0}<br>公钥：{1}<br>", xmlPrivateKeys, xmlPublicKey));

            string encryptConent = SysCrypto.RSAEncrypt(xmlPublicKey, content);
            Response.Write(string.Format(@"加密以后的内容为：{0}<br>", encryptConent));
            encryptConent = "NyQHRNBkHXbkOtw+YWzr+IVViTbUwVgOjpSMEFiFGMTh+zg5NTCSekE2vokg6jQd8VXFaIfDepQoMRFKFd6gDmExu65m45gK/896tJDo6OSpxhKpAgLgB3m7VEYyFJBqdREGSjCrUwR26wlCRri1A/rVAMWpy16X8rnFqJgIWb4=";

            DateTime startTime = DateTime.Now;
            Response.Write(string.Format(@"解密以后的内容为：{0}<br>", SysCrypto.RSADecrypt(xmlPrivateKeys, encryptConent)));
            Response.Write(DateTime.Now - startTime);

            Response.Write("<br>" + 13717705584.ToString("NNN******nn"));

        }
    }
}